package listnode;


import listnode.data.GenerateRandomListNode;
import listnode.data.ListNode;

/**
 * 相交链表
 *
 *  1. hashset contins
 *  2. 双指针
 */
public class GetIntersection {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA==null||headB==null){
            return null;
        }

        ListNode pa=headA;
        ListNode pb=headB;

        while(pa!=pb){
            pa=pa==null?headB:pa.next;
            pb=pb==null?headA:pb.next;
        }

        return pa;
    }


    public static void main(String[] args) {
        System.out.println("Hello and welcome!");
    }
}
